package com.hrt.datasender.process.strategy.hj212;

import com.btcode.db.result.Row;
import com.hrt.datasender.datadao.model.BcSendPlatformModel;
import com.hrt.datasender.mq.MqKit;
import com.hrt.datasender.mq.model.PacketModel;
import com.hrt.datasender.process.indentity.hj212.MessageModel;
import com.hrt.datasender.process.strategy.IProcessStrategy;
import com.hrt.datasender.process.strategy.hj212.util.StrategyUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class Com1011Process implements IProcessStrategy  {

    @Override
    public String getCommandId() {
        // TODO Auto-generated method stub
        return "1011";
    }

    @Override
    public String getStrategyName() {
        return "提取现场机时间";
    }

    @Override
    public Object packet(List<Row> data, BcSendPlatformModel platform) {
        return null;
    }

    @Override
    public Object packetReissue(List<Row> data, BcSendPlatformModel platform) {
        return null;
    }

    @Override
    public void decode(MessageModel data, BcSendPlatformModel sendPlatform) {
        String msg = data.getMsg() + "";
        /**
         * 返回请求应答
         */
        StrategyUtil.responseMsg(sendPlatform,msg,"0","");
        /**
         * 读取本地系统时间，构造报文返回
         * QN=20160801085857223;ST=32;CN=1011;PW=123456;MN=010000A8900016
         * F000169DC0;Flag=4;CP=&&PolId=w01018;SystemTime=20160801085857&&
         */
        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
        String response = msg.substring(6,msg.length()-6);
        response = response + ";SystemTime=" + sf.format(new Date()) + "&&";

        Object packetMsg = StrategyUtil.getCompleteMsg(response);
        PacketModel packetModel = new PacketModel();
        packetModel.setIp(sendPlatform.getIp());
        packetModel.setPort(sendPlatform.getPort());
        packetModel.setMn(sendPlatform.getMn());
        packetModel.setMsg(packetMsg);
        MqKit.productMsgToRecriminateMQ(packetModel);
        StrategyUtil.responseMsg(sendPlatform,msg,"1","1");

    }

}
